# -*- coding: utf-8 -*-
# Author   : ZhangQing
# Time     : 2025-07-15 22:58
# File     : smart_alerts.py
# Project  : dynamic-portfolio-optimizer
# Desc     :

# src/alerts/smart_alerts.py
class SmartAlertSystem:
    """智能告警系统"""

    def __init__(self):
        self.thresholds = {
            'max_drawdown': -0.1,  # 最大回撤阈值
            'volatility': 0.3,  # 波动率阈值
            'sharpe_ratio': 0.5  # Sharpe比率阈值
        }

    def check_alerts(self, portfolio_metrics):
        """检查告警条件"""
        alerts = []

        if portfolio_metrics['max_drawdown'] < self.thresholds['max_drawdown']:
            alerts.append({
                'type': 'high_risk',
                'message': f"⚠️ 最大回撤过大: {portfolio_metrics['max_drawdown']:.2%}",
                'severity': 'critical'
            })

        if portfolio_metrics['volatility'] > self.thresholds['volatility']:
            alerts.append({
                'type': 'high_volatility',
                'message': f"📊 组合波动率过高: {portfolio_metrics['volatility']:.2%}",
                'severity': 'warning'
            })

        return alerts

